package config

import (
	"log"
	"os"
	"tosServer/internal/pkg/logger"

	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
)

func init() {
	configPath := os.Getenv("CONFIG_PATH")
	if configPath == "" {
		configPath = "./configs"
	}

	viper.SetConfigName("config")
	viper.SetConfigType("yaml")
	viper.AddConfigPath(configPath)

	err := viper.ReadInConfig()
	if err != nil {
		log.Fatalln(err)
	}

	viper.WatchConfig()

	viper.OnConfigChange(func(e fsnotify.Event) {
		logger.Info("配置已更新:", e.Name)
	})
}
